<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<!DOCTYPE html>
<html>
<head>
	<base href="<%=basePath%>">
<meta charset="UTF-8">
<link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />

<script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
<script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>
	<script type="text/javascript">
		$(function () {
			//给添加按钮添加点击事件
			$("#createDicValueBtn").click(function () {
				window.location.href = "settings/dictionary/value/tosave.do";
			});
			//给修改按钮添加点击事件
			$("#editDicValueBtn").click(function () {
				var ck = $("input[type='checkbox']:gt(0):checked");
				if(ck.length == 0){

					layer.msg("请选择要修改的数据")

					return false;
				}
				if(ck.length > 1){
					layer.msg("一次只能选择一条数据")
					return false;
				}
				if(ck.length == 1){
					var id = ck.val();
					// window.location.href = "settings/dictionary/value/getDicType.do?id="+id;
					layer.confirm('是否确认编辑？', {
						btn: ['取消','确认'] //按钮
					}, function(){
						layer.msg('编辑已取消');
					}, function() {
						layer.msg('编辑已就绪');
						window.location.href = "settings/dictionary/value/getDicType.do?id="+id;
					})

				}
			});

			//复选框的全选全不选
			$("#checkAll").click(function () {
				$("#tBody input[type='checkbox']").prop("checked", this.checked);
			});
			$("input[type='checkbox']:gt(0)").click(function () {
				if ($("input[type='checkbox']:gt(0):checked").length == $("input[type='checkbox']:gt(0)").length) {
					$("#checkAll").prop("checked", true);
				} else {
					$("#checkAll").prop("checked", false);
				}
			});

			//给删除按钮添加点击事件
			$("#deleteDicValueBtn").click(function () {
				//如果没有被选中则提示用户
				var ck = $("input[type='checkbox']:checked");
				if (ck.length == 0) {
					// layer.msg("请选择要删除的数据");
					layer.msg("请选择要删除的数据");
					return false;
				}
				//定义一个list集合用于保存ck的value值
				var codes = [];
				//获取被选中的复选框的属性值
				for (var i = 0; i < ck.length; i++) {
					var code = ck[i].value;
					codes.push(code);
				}
				//将数组转为json进行传递
				var codesjson = JSON.stringify(codes);
				//window.confirm("是否确认删除?");取消返回false，确定返回true
				//layer弹窗确认取消
				layer.confirm('是否确认删除？', {
					btn: ['取消','确认'] //按钮
				}, function(){
					window.location.href = "settings/dictionary/value/index.do";
					// layer.msg('删除已取消');
				}, function() {
					$.ajax({
						url: "settings/dictionary/value/remove.do",
						type: "post",
						data: codesjson,
						dataType: "json",
						contentType: "application/json;charset=utf-8",
						success: function (data) {
							if (data.successCode == 0) {
								layer.msg("删除失败");
							} else {
								window.location.href = "settings/dictionary/value/index.do";
							}
						}
					})
				})


			});
		})
	</script>
</head>
<body>

	<div>
		<div style="position: relative; left: 30px; top: -10px;">
			<div class="page-header">
				<h3>字典值列表</h3>
			</div>
		</div>
	</div>
	<div class="btn-toolbar" role="toolbar" style="background-color: #F7F7F7; height: 50px; position: relative;left: 30px;">
		<div class="btn-group" style="position: relative; top: 18%;">
		  <button id="createDicValueBtn" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> 创建</button>
		  <button id="editDicValueBtn" type="button" class="btn btn-default"><span class="glyphicon glyphicon-edit"></span> 编辑</button>
		  <button id="deleteDicValueBtn" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-minus"></span> 删除</button>
		</div>
	</div>
	<div style="position: relative; left: 30px; top: 20px;">
		<table class="table table-hover">
			<thead>
				<tr style="color: #B3B3B3;">
					<td><input type="checkbox" id="checkAll"/></td>
					<td>序号</td>
					<td>字典值</td>
					<td>文本</td>
					<td>排序号</td>
					<td>字典类型编码</td>
				</tr>
			</thead>
			<tbody id="tBody">
				<c:forEach items="${requestScope.dicTypeList}" var="dv" varStatus="vs">
					<c:if test="${vs.count%2==0}">
						<tr class="active">
					</c:if>
					<c:if test="${vs.count%2!=0}">
						<tr>
					</c:if>
						<td><input type="checkbox" value="${dv.id}"/></td>
						<td>${vs.count}</td>
						<td>${dv.value}</td>
						<td>${dv.text}</td>
						<td>${dv.orderNo}</td>
						<td>${dv.typeCode}</td>
					</tr>
				</c:forEach>

			</tbody>
		</table>
	</div>
	
</body>
</html>